package com.yjha.lzmarathonsys.enums;

import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

@Getter
public enum StateEnum {

    // 审批通过
    APPROVAL_PASS(-2, "审批通过", null),
    // 审批不通过
    APPROVAL_NOT_PASS(-3, "审批不通过", AuditRoleEnums.WRITER.getCode()),
    // 系统管理员
    ADMIN(10000, "系统管理员", "admin"),
    // 未提交
    UN_SUBMIT(-1, "未提交", null),
    // 待提交
    SUBMIT(0, "待提交", AuditRoleEnums.WRITER.getCode()),
    // 审批中
    APPROVAL(1, "审批中", AuditRoleEnums.APPROVER.getCode()),
    // 审核中
    CHECK(2, "审核中", AuditRoleEnums.AUDITOR.getCode()),
    // 负责人审批中
    DEPUTY(3, "审批中", AuditRoleEnums.PRINCIPAL.getCode()),
    // 核准中
    APPROVAL_CHECK(4, "校核中", AuditRoleEnums.CHECKER.getCode()),
    // 检测中
    CHECK_DETECT(5, "检测中", AuditRoleEnums.CHECKER_PERSON.getCode()),
    // 记录中
    RECORD(6, "记录中", AuditRoleEnums.RECORDER.getCode()),
    // 抽样中
    SAMPLE(9, "抽样中", AuditRoleEnums.SAMPLER.getCode()),
    // 单位负责人审批中
    DEPARTMENT_HEAD(10, "单位负责人审批中", AuditRoleEnums.DEPARTMENT_HEAD.getCode()),
//    PRINCIPAL(11, "项目负责人", AuditRoleEnums.PRINCIPAL.getCode()),
    // 参加人
    PARTICIPANT(12, "参加人", AuditRoleEnums.PARTICIPANT.getCode()),
    // 技术负责人意见
    TECHNICAL_HEAD(13, "技术负责人意见", AuditRoleEnums.TECHNICAL_HEAD.getCode()),
    // 站长批示
    CHECK_OPINION(14, "站长批示", AuditRoleEnums.CHIEF.getCode()),
    //汇总人
    AGGREGATORS(15,"汇总人审核",AuditRoleEnums.AGGREGATORS.getCode()),
    //
    CHECKER(16,"校核人",AuditRoleEnums.AGGREGATORS.getCode()),
    DEPARTMENT_HEAD_PERSON(17, "部门负责人审批", AuditRoleEnums.DEPARTMENT_HEAD_PERSON.getCode()),
    // 企业负责人审批
    DEPARTMENT(25, "承担部门负责人审批",AuditRoleEnums.DEPARTMENT.getCode()),
    COMPANY_HEAD(18, "企业负责人审批", AuditRoleEnums.COMPANY_HEAD.getCode()),
    IDENTIFICATION_SERVICE(19, "鉴定科审批", AuditRoleEnums.IDENTIFICATION_SERVICE.getCode()),
    SAMPLER_PER(20, "验样中", AuditRoleEnums.SAMPLER_PER.getCode()),
    SAMPLE_SUPPLIER(21, "供样单位负责人审批", AuditRoleEnums.SAMPLE_SUPPLIER.getCode()),
    SAMPLING_PER(22, "抽样中", AuditRoleEnums.SAMPLING_PER.getCode()),
    SAMPLE_MANAGER(23, "样品管理员审批", AuditRoleEnums.SAMPLE_MANAGER.getCode()),
    // 移交人
    TRANSFER_PERSON(24, "移交人移交", AuditRoleEnums.TRANSFER_PERSON.getCode()),
    // 接收人
    RECEIVER(26, "接收人接收", AuditRoleEnums.RECEIVER.getCode()),
    ;



    private int state;
    private String desc;
    private String auditRole;

    StateEnum(int state, String desc, String auditRole) {
        this.state = state;
        this.desc = desc;
        this.auditRole = auditRole;
    }

    private static final Map<Integer, StateEnum> stateMapping = Arrays.stream(StateEnum.values())
            .collect(Collectors.toMap(StateEnum::getState, e -> e));

    private static final Map<String, StateEnum> auditRoleMapping = Arrays.stream(StateEnum.values())
            .collect(Collectors.toMap(StateEnum::getAuditRole, e -> e, (k1, k2) -> k1));

    public static StateEnum getStateEnum(int state) {
        return stateMapping.get(state);
    }

    public static StateEnum getStateEnumByAuditRole(String auditRole) {
        return auditRoleMapping.get(auditRole);
    }

}
